.TH srand 3 "" "" ""
.SH SYNOPSIS
rand, srand \- pseudo-random numbers
.SH ANSI_SYNOPSIS
#include <stdlib.h>
.br
int rand(void);
.br
void srand(unsigned int 
.IR seed );
.br
int rand_r(unsigned int *
.IR seed );
.br
.SH TRAD_SYNOPSIS
#include <stdlib.h>
.br
int rand();
.br

void srand(
.IR seed )
.br
unsigned int 
.IR seed ;
.br

void rand_r(
.IR seed )
.br
unsigned int *
.IR seed ;
.br
.SH DESCRIPTION
.BR rand 
returns a different integer each time it is called; each
integer is chosen by an algorithm designed to be unpredictable, so
that you can use 
.BR rand 
when you require a random number.
The algorithm depends on a static variable called the ``random seed'';
starting with a given value of the random seed always produces the
same sequence of numbers in successive calls to 
.BR rand .

You can set the random seed using 
.BR srand ;
it does nothing beyond
storing its argument in the static variable used by 
.BR rand .
You can
exploit this to make the pseudo-random sequence less predictable, if
you wish, by using some other unpredictable value (often the least
significant parts of a time-varying value) as the random seed before
beginning a sequence of calls to 
.BR rand ;
or, if you wish to ensure
(for example, while debugging) that successive runs of your program
use the same ``random'' numbers, you can use 
.BR srand 
to set the same
random seed at the outset.
.SH RETURNS
.BR rand 
returns the next pseudo-random integer in sequence; it is a
number between 
.BR 0 
and 
.BR RAND_MAX 
(inclusive).

.BR srand 
does not return a result.
.SH NOTES
.BR rand 
and 
.BR srand 
are unsafe for multi-thread applications.
.BR rand_r 
is MT-Safe and should be used instead.
.SH PORTABILITY
.BR rand 
is required by ANSI, but the algorithm for pseudo-random
number generation is not specified; therefore, even if you use
the same random seed, you cannot expect the same sequence of results
on two different systems.

.BR rand 
requires no supporting OS subroutines.
.SH SOURCE
src/newlib/libc/stdlib/rand.c
